<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>组件中使用v-for</title>
    <!--引入Vue库-->
    <script src="vue.js"></script>
  </head>
  <body>
    <div id="app">
      <my-component
        v-for="(item,index) in items"
        :name="item.bookName"
        :index="index"
        :key="item.id"
      ></my-component>

      
    </div>
    <script>
      // 注册
      Vue.component("my-component", {
        template: `<h1>{{index}}  -  {{ name }}</h1>`,
        props: ["index", "name"],
      });
      // 创建根实例
      new Vue({
        el: "#app",
        data() {
          return {
            items: [
              { id: 1, bookName: "HTML5+CSS3移动Web开发实战" },
              { id: 2, bookName: "零基础学Python" },
              { id: 3, bookName: "数学之美" },
            ],
          };
        },
      });
    </script>
  </body>
</html>
